package dao;

import dao.exception.NotEntityFoundException;
import entity.Formulario;
import java.util.Calendar;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.persistence.TemporalType;

/**
 *
 * @author Juan Sebastian Hernández Serrato
 */
public class FormularioDAO extends AbstractDataAccessObject<Formulario> {
    
    public FormularioDAO(){
        super(Formulario.class);
    }
    
    public Formulario findFormularioActual(EntityManager em) throws NotEntityFoundException{
        Query query = em.createNamedQuery("formularioActivo")
                .setParameter("hoy", Calendar.getInstance(), TemporalType.DATE);
        Formulario formulario = null;
        try {
            formulario = (Formulario) query.getSingleResult();
        } catch (NoResultException e) {
            throw new NotEntityFoundException();
        }
        return formulario;
    }
}
